package com.qn.wechat.controller;

import com.jeesuite.mybatis.plugin.pagination.Page;
import com.jeesuite.springweb.model.WrapperResponse;
import com.oneplatform.base.exception.AssertUtil;
import com.oneplatform.base.model.PageResult;
import com.qn.wechat.ifservice.dto.SBPromoteDto;
import com.qn.wechat.ifservice.dto.WXReplyConfigDto;
import com.qn.wechat.ifservice.dto.para.ReplyContentConfigPara;
import com.qn.wechat.ifservice.dto.para.SBPromoteQeuryPara;
import com.qn.wechat.service.ReplyContentConfigService;
import com.qn.wechat.service.SBPromoteService;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "/replycontent")
public class ReplyContentConfigController {

    @Resource
    ReplyContentConfigService replyContentConfigService;

    @ApiOperation(value = "获取回复配置列表")
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public @ResponseBody
    PageResult<WXReplyConfigDto> getList(@ModelAttribute ReplyContentConfigPara para) {
        Page<WXReplyConfigDto> page =replyContentConfigService.getList(para);
        return new PageResult<WXReplyConfigDto>(page.getPageNo(), page.getPageSize(), page.getTotal(), page.getData());
    }

    @ApiOperation(value = "获取配置")
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public @ResponseBody
    WrapperResponse<WXReplyConfigDto> get(@ModelAttribute ReplyContentConfigPara para) {

        WrapperResponse<WXReplyConfigDto> response = new WrapperResponse<>();
        para.setPageNo(1);
        para.setPageSize(1);
        AssertUtil.notBlank(para.getId(),  "id不能为空");

        Page<WXReplyConfigDto> page = replyContentConfigService.getList(para);
        if (page != null && page.getData() != null && page.getData().size() > 0) {
            response.setData(page.getData().get(0));
        }

        return response;

    }

    @ApiOperation(value = "保存配置")
    public @ResponseBody
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    WrapperResponse<String> save(@RequestBody WXReplyConfigDto dto) {
        return replyContentConfigService.save(dto);
    }
}
